package com.zj.small.service.impl;

import com.zj.small.service.SendEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

import java.util.concurrent.ThreadLocalRandom;
@Service
public class SendEmailImpl implements SendEmail {
    @Autowired
    private JavaMailSenderImpl javaMailSender;
    @Value("${spring.mail.username}")
    private String from;
    public String sendMessage(String toEmail){

        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("欢迎加入叽里咕噜");
        String key = String.valueOf(ThreadLocalRandom.current().nextInt(100000, 1000000));
        message.setText("很高兴您加入我们！叽里咕噜是您进行信息问答的最佳场所。\n请使用以下数字作为您的激活码:\n"+key);
        message.setFrom(from);//发送者的邮箱地址
        message.setTo(toEmail); //接收者的邮箱地址
        javaMailSender.send(message);
        return key;
    }
    // 反馈信息   + token
    public String sendFeedback(String toEmail, String feedback) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("叽里咕噜收到反馈信息: ");
        message.setText("反馈信息: "+feedback + "\n感谢您的反馈，我们会尽快处理！！！\n感谢您为叽里咕噜做的贡献！！");
        message.setFrom(from);//发送者的邮箱地址
        message.setTo(toEmail); //接收者的邮箱地址
        javaMailSender.send(message);
        return "";
    }
}
